package zhieasy.cn.service.common.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zhieasy.cn.model.common.WechatUser;
import zhieasy.cn.model.common.WechatUserRole;
import zhieasy.cn.persistence.mapper.common.WechatUserRoleMapper;
import zhieasy.cn.service.common.WechatUserRoleService;

/**
 * @author DaHang
 * @date 2020/8/16 16:47
 */
@Service
public class WechatUserRoleServiceImpl extends ServiceImpl<WechatUserRoleMapper, WechatUserRole> implements WechatUserRoleService {
    @Autowired
    WechatUserRoleMapper wechatUserRoleMapper;

    @Override
    public boolean setStudentRole(WechatUser wechatUser, Long roleId) {
        return setWechatUserRole(wechatUser,roleId);

    }

    @Override
    public boolean setWechatUserRole(WechatUser wechatUser, Long roleId) {
        WechatUserRole wechatUserRole = new WechatUserRole();
        wechatUserRole.setRoleId(roleId);
        wechatUserRole.setUserId(wechatUser.getWxOpenId());
        int insert = wechatUserRoleMapper.insert(wechatUserRole);
        return insert == 1;
    }

    @Override
    public boolean initWechatUserRole(WechatUser wechatUser) {
        return setWechatUserRole(wechatUser,7L);
    }

    @Override
    public boolean setStudentRoleForNormalUser(WechatUser wechatUser) {

        return setWechatUserRole(wechatUser,2L);
    }

    @Override
    public boolean setTeacherRoleForNormalUser(WechatUser wechatUser) {
        return setWechatUserRole(wechatUser,4L);
    }
}
